<?php session_start(); 
ob_start();
?>

<html>
    <head>
        
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <link rel="stylesheet" type="text/css" href='../public/css/style.css'>
        <title>Nguyen Quoc Thong</title>
      </head>
 <body id="bang">
        <div id="banner">
            
        </div>

        <div id="menu">
            
            <ul id="a">
                <li><a href="#">HOME</a>  </li>
                <li><a href="#">ABOUT</a> </li>
                <li><a href="#">FORUMS</a> </li>
                <li><a href="#">CONTACT</a> </li>
                    <li><a href='http://localhost:92/nqt-web2/public/login.php/'>LOGIN</a>
                        
               <?php
        if (isset($_GET["logout"]) && $_GET["logout"] == true) {
            unset($_SESSION["id"]);
            header("location:login.php");
        }
        ?>
            </ul>
            
        </div>


            <br>


        <div id="page">  
            
            <?php if (isset($_SESSION['id'])): ?>
                <a href="index.php?logout=true"><h3>Logout</h3></a>
            <?php endif; ?>
               <br>
            <div class="ajax_show"></div>
            <br>  
          <?php
          
        require_once '../model/db.php';
        require_once '../model/works.php';
        require_once '../model/pagination.php';
        $works = new works();
        $paginations = new Pagination();
        ?>
             <div style="position: fixed; width: 250px; margin:auto;">
        <div id="list">
        <?php
        if (!isset($_GET["page"]))
            $page = 1;
        else
            $page = $_GET["page"];
        $list_of_works = $works->select($page);
        $total = $works ->count();
        echo $paginations ->Display($page, $total,null,"index.php");
        ?>
        </div>  </div> 
        <br>
        
        <div class="table">
           

        <table border="1px">
            <tr>
                <td>stt </td>
                <td>images </td>
                <td>noi dung </td>
                <td>Link</td>
                <td>Edit</td>
            </tr>
            <?php foreach ($list_of_works as $list1): ?>

                <tr>
                    <td><?php echo $list1["id"]; ?></td>
                    <td><img src="<?php echo $list1["image"]; ?>" width="100"></td>
                    <td><?php echo $list1["name"]; ?></td>
                  
                    <td><a href='<?php echo $list1["url"]; ?>'><?php echo $list1["url"]; ?></td>
                     <?php if (isset($_SESSION['id']) && $_SESSION['id'] == 1) : ?>
                    <td><a href="edit.php?id=<?php echo $list1["id"];?>">  edit  </a> <br>
                        <?php //wiew.php?id=<?php echo $list1["id"];?>
                        <a href="#" class="ajax_view" id_keyword ="<?php echo $list1['id'] ?>"> view  </a><br>
                        <a href="edit.php">  deleter </a>
                    
                    </td>
                </td>
                            <?php endif; ?>
                
                        </tr>
                   
             
            <?php endforeach; ?>
        </table></div>
        <br>
     
<div class="footer">
  
    
                    <table style="font-size: 9px; color: white;">
                        <tr><td>Design by :</td><td> Nguyen Quoc Thong</td></tr>
                      
                    </table>            
                </div>
 <script type="text/javascript" >
            $(document).ready(function() {
                $(".ajax_view").click(function() {
                    id_keyword = $(this).attr('id_keyword');                    
                    url = "ajax.php?id_keyword="+id_keyword;
                    $.ajax({
                        url: url,
                        }).done(function(data) {
                            console.log(data);
                    });
                });
            });
        </script>
</body>
</html>
<?php ob_end_flush();?>    